package org.brisling.common.util;

public class GenerateTypedClass {

	private static GenerateTypedClass clazz;
	
	private GenerateTypedClass(){};
	
	public static GenerateTypedClass getInstance(){
		if(clazz==null)
			clazz = new GenerateTypedClass();
		return clazz;
	}
	public static Object getTypedClass(String str,Object dataObj){
		getInstance();
		//如果为null或空字符串，返回null
		String dataValue = null;
		if(dataObj==null ){
			return null;
		}
		
		dataValue = dataObj.toString().trim();
		if(dataValue.compareTo("")==0){
			return null;
		}
		
		Object _clazz = null;
		switch(str){
		case "java.lang.Integer"
			:_clazz= Integer.parseInt(dataValue.toString());
			break;
		case "java.lang.Long"	
			:_clazz =Long.parseLong(dataValue.toString());
			break;
		case "java.lang.String"
			:_clazz= dataValue;
			break;
		case "java.util.Date"
			:_clazz = DateUtil.jsonStr2Date(dataObj.toString());
		case "java.lang.Double"
		:_clazz = Double.parseDouble(dataObj.toString());
		};
		
		return _clazz;
	}
}
